"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.instance2Object = exports.hansMeta = exports.Column = exports.Entity = exports.getMeta = void 0;
function getMeta(constructor) {
    return constructor.prototype.$REDIS_META || (constructor.prototype.$REDIS_META = {
        name: '',
        // 这里的两个字段是为配合 token 使用
        keys: [
            // 生成时间
            'iat',
            // 超时时间
            'exp'
        ],
        MetaDatas: {
            iat: Number,
            exp: Number
        }
    });
}
exports.getMeta = getMeta;
function Entity(name, options) {
    var metaName = '';
    if (name && typeof name === 'string') {
        metaName = name;
    }
    else if (!name && options && typeof options.name === 'string') {
        metaName = options.name;
    }
    return function (constructor) {
        var meta = getMeta(constructor);
        meta.name = metaName || constructor.name;
    };
}
exports.Entity = Entity;
function Column() {
    return function (target, propertyKey) {
        var meta = getMeta(target.constructor);
        var reflectMetadataType = Reflect && Reflect.getMetadata ? Reflect.getMetadata("design:type", target, propertyKey) : undefined;
        meta.keys.push(propertyKey);
        meta.MetaDatas[propertyKey] = reflectMetadataType;
    };
}
exports.Column = Column;
function hansMeta(constructor) {
    return !!constructor.prototype.$REDIS_META;
}
exports.hansMeta = hansMeta;
// 类实例 转 普通对象
function instance2Object(target) {
    if (hansMeta(target.constructor)) {
        var meta = getMeta(target.constructor);
        var result_1 = {};
        meta.keys.forEach(function (key) {
            result_1[key] = target[key] || '';
        });
        return result_1;
    }
    return target;
}
exports.instance2Object = instance2Object;
